package com.kun.framework.queue.core;


import com.fasterxml.jackson.core.type.TypeReference;
import com.kun.framework.core.util.JacksonUtil;
import com.kun.framework.data.persistence.rule.SingletonFileRuler;
import com.kun.framework.queue.dto.KunMessage;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.concurrent.ConcurrentLinkedQueue;

/**
 * 默认坤坤消息队列实现
 *
 * @author gzc
 * @since 2024/8/21
 **/
public class DefaultMessageQueue extends DefaultAbstractMessageQueue<KunMessage<String>> {
    private static final Logger log = LoggerFactory.getLogger(DefaultMessageQueue.class);

    private static final String FILE_NAME = "default-message-queue";

    public DefaultMessageQueue() {
        super(new SingletonFileRuler(FILE_NAME));
    }

//    @Override
//    public void init() {
//        super.init();
//    }

    @Override
    public ConcurrentLinkedQueue<KunMessage<String>> dataStrConvertObj(String jsonStr) {
        TypeReference<ConcurrentLinkedQueue<KunMessage<String>>> reference = new TypeReference<>() {};
        return JacksonUtil.parseArray(jsonStr, reference);
    }



    @Override
    public void destroy() {
        System.out.println("消息队列未处理完的消息数量 -> " + super.QUEUE.size());
    }
}
